﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace RayTracing
{
    class ShiftedObject : Geometry
    {
        public Geometry geometry; //Geometry of the object
  
        public P3 xyz;
       // public P3 hpr;
        public P3 scale;
        
        public ShiftedObject(Geometry geometry,P3 xyz,P3 scale) //Creates a SceneObject with a geometry, texture, and skin
        {
      
            this.geometry = geometry;
    
            this.xyz = xyz;
          //  this.hpr = hpr;
              this.scale = new P3(1/scale.x,1/scale.y,1/scale.z);

           
        }

        public P3 toInnerP(P3 p)
        {
            P3 newp = P3.mul(p,scale);
            newp = P3.sub(newp,xyz);
           return newp;
        }

        public P3 toOuterP(P3 p)
        {
            return P3.add(p,xyz);
        }

        public P3 toInnerD(P3 p)
        {
            P3 newp = P3.mul(p, scale);
            return newp;
        }

        public float distance(Ray ray)                                   //Gets the distance of a ray using geometry
        {
            Ray newray = new Ray(toInnerP(ray.origin),P3.normalize(toInnerD(ray.direction)));

            return geometry.distance(newray);
        }

        public P2 toP2(P3 p)
        {
            P3 newp = toInnerP(p);
            return geometry.toP2(newp);
        }
        public P3 normal(P3 p)
        {
            P3 newp = toInnerP(p);

            return geometry.normal(newp);

        }
        
    }
  }

